1. Field of the Invention
The present invention relates generally to computer operating systems and more particularly to a method for controlling access to system resources.
2. Description of the Prior Art
In multithreaded operating systems wherein several different transactions are being processed at the same time, certain system resources, such as regions of modifiable code or locations in system memory, must be shared, i.e., accessible by multiple processing threads. During some operations, such as reading the contents of a memory location, a given resource may be available to more than one thread at the same time. Some operations, however, such as writing new information into a memory location, requires the thread engaged in writing the information to have exclusive access to the resource.
To prevent another thread from gaining access to the resource during such an exclusive operation, operating systems typically utilize a lock mechanism. While one thread is performing an exclusive operation on a resource, all other threads are prevented from gaining access to that resource. A problem in prior art systems involves how to handle the situation where a thread tries and fails to obtain access to a locked resource.
In some prior art operation systems, the thread may simply wait in an idle mode until the desired resource becomes available to it. No useful work is being done by the waiting thread during this period. Other prior art methods, in an attempt to improve the utilization of the system processors, remove the thread from execution and reschedule another thread. This act of rescheduling is itself an expensive operation in terms of processor time. It requires that the state of the thread being removed be saved, a determination be made as to which other thread should be scheduled, the new thread's state must be retrieved and loaded and execution of the new thread initiated. When the resource later becomes available, a similar rescheduling process must be performed again to return the removed thread to execution.
Under either of these techniques, when a resource is contended for, significant overhead costs are incurred. Also, under either technique there remains the risk of the system arriving at a deadlock condition, and therefore becoming non-functional.